package top.sdaily.web.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.sdaily.core.mybatis.Conditions;
import top.sdaily.core.utils.IdGeneratorUtils;
import top.sdaily.mapper.CityMapper;
import top.sdaily.web.model.City;
import top.sdaily.web.service.CityService;

import java.util.List;

/**
 * Created by TsujiShiki on 2017/02/17.
 */
@Service
@Transactional
public class CityServiceImpl implements CityService {

    @Autowired
    private CityMapper cityMapper;

    @Override
    public List<City> getAllCityByProvince(String provinceId) {
        return cityMapper.findList(new Conditions(City.class).eq("province_id", provinceId));
    }

    @Override
    public City getCityById(String id) {
        return cityMapper.findOne(new Conditions(City.class).id(id));
    }

    @Override
    public int insertCity(City city) {
        city.setPkid(IdGeneratorUtils.fresh());
        return cityMapper.insert(city);
    }

    @Override
    public int updateCity(City city) {
        return cityMapper.update(city);
    }
}
